{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "ST_data_xls_1 = pd.read_excel(\"ST公司数据.xls\")\n",
    "ST_data_xls_2 = pd.read_excel(\"ST公司数据负债.xls\")\n",
    "ST_Plus_data_xls_1 = pd.read_excel(\"ST+公司数据.xls\")\n",
    "ST_Plus_data_xls_2 = pd.read_excel(\"ST+公司数据负债.xls\")\n",
    "NST_data_xls_1 = pd.read_excel(\"非ST公司数据.xls\")\n",
    "NST_data_xls_2 = pd.read_excel(\"非ST公司数据负债.xls\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "F:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py:2: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \n",
      "F:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py:4: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  after removing the cwd from sys.path.\n",
      "F:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py:7: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  import sys\n",
      "F:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py:9: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  if __name__ == '__main__':\n",
      "F:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py:12: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  if sys.path[0] == '':\n",
      "F:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py:14: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \n"
     ]
    }
   ],
   "source": [
    "# 读取ST上市公司数据\n",
    "ST_data_1 = ST_data_xls_1.ix[:18,\n",
    "            ['收盘价_Clpr', '流通股_Trdshr', '已上市流通股_Lsttrdshr', '年收益率_Yrret', '年无风险收益率_Yrrfret', '每股净资产(元/股)_NAPS']].values\n",
    "ST_data_2 = ST_data_xls_2.ix[:18, ['流动负债合计(元)_TotCurLia', '非流动负债合计(元)_TotNCurLia', '负债合计(元)_TotLiab']].values\n",
    "\n",
    "# 读取ST*上市公司数据\n",
    "ST_Plus_data_1 = ST_Plus_data_xls_1.ix[:18,\n",
    "            ['收盘价_Clpr', '流通股_Trdshr', '已上市流通股_Lsttrdshr', '年收益率_Yrret', '年无风险收益率_Yrrfret', '每股净资产(元/股)_NAPS']].values\n",
    "ST_Plus_data_2 = ST_Plus_data_xls_2.ix[:18, ['流动负债合计(元)_TotCurLia', '非流动负债合计(元)_TotNCurLia', '负债合计(元)_TotLiab']].values\n",
    "\n",
    "# 读取非ST上市公司数据\n",
    "NST_data_1 = NST_data_xls_1.ix[:36,\n",
    "            ['收盘价_Clpr', '流通股_Trdshr', '已上市流通股_Lsttrdshr', '年收益率_Yrret', '年无风险收益率_Yrrfret', '每股净资产(元/股)_NAPS']].values\n",
    "NST_data_2 = NST_data_xls_2.ix[:36, ['流动负债合计(元)_TotCurLia', '非流动负债合计(元)_TotNCurLia', '负债合计(元)_TotLiab']].values\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 3.8   4.77  8.44  7.89 26.96  2.76  6.08  7.66  3.36  6.22  4.15  2.\n",
      "  4.9   2.35  4.52  1.3   4.73  7.02  4.76]\n",
      "[4.75986366e+07 1.31927546e+08 7.64499579e+07 3.22101155e+08\n",
      " 1.13781498e+08 9.33883843e+07 6.33638731e+07 3.24132042e+07\n",
      " 3.56165513e+09 4.25989575e+07 1.05619792e+08 3.47699175e+09\n",
      " 3.62354029e+08 2.53993269e+07 7.22089177e+07 3.60489946e+08\n",
      " 1.28833295e+08 1.59592981e+07 1.01856101e+09]\n"
     ]
    }
   ],
   "source": [
    "print(ST_data_1[:,0])\n",
    "print(ST_data_2[:,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 收盘价_Clpr\n",
    "ST_Clpr_list = ST_data_1[:, 0]\n",
    "# 流通股_Trdshr\n",
    "ST_Trdshr_list = ST_data_1[:, 1]\n",
    "# 已上市流通股_Lsttrdshr\n",
    "ST_Lsttrdshr_list = ST_data_1[:, 2]\n",
    "# 每股净资产\n",
    "ST_NAPS_list = ST_data_1[:, 5]\n",
    "\n",
    "# 股权市场价值列表\n",
    "ST_E_list = ST_Clpr_list * ST_Lsttrdshr_list + (ST_Trdshr_list - ST_Lsttrdshr_list) * ST_NAPS_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 3.8   4.77  8.44  7.89 26.96  2.76  6.08  7.66  3.36  6.22  4.15  2.\n",
      "  4.9   2.35  4.52  1.3   4.73  7.02  4.76]\n",
      "[4.37412524e+08 3.80160000e+08 2.41320000e+08 2.02445880e+08\n",
      " 1.29800000e+08 5.08837238e+08 2.35148140e+08 1.95600000e+08\n",
      " 5.33780000e+08 3.94793708e+08 3.28861441e+08 1.28302099e+09\n",
      " 3.40565550e+08 1.23247000e+09 4.46383080e+08 1.46432840e+09\n",
      " 3.41010182e+08 1.60910082e+08 6.87282040e+08]\n",
      "[4.37412524e+08 3.80160000e+08 2.41320000e+08 2.02445880e+08\n",
      " 1.29800000e+08 5.08837238e+08 2.35148140e+08 1.95600000e+08\n",
      " 5.33780000e+08 3.94793708e+08 3.18371441e+08 7.55043154e+08\n",
      " 3.40565550e+08 1.23247000e+09 4.46383080e+08 1.06432840e+09\n",
      " 3.40910182e+08 1.55679074e+08 6.87282040e+08]\n",
      "[ 2.03  0.51  0.25  0.34  0.06  0.28  1.27  0.01  0.54  0.16  0.17  1.66\n",
      "  0.88  0.24  0.99  1.36  0.73  0.6  -0.23]\n"
     ]
    }
   ],
   "source": [
    "print(ST_Clpr_list)\n",
    "print(ST_Trdshr_list)\n",
    "print(ST_Lsttrdshr_list)\n",
    "print(ST_NAPS_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# ST公司数据\n",
    "# 收盘价_Clpr\n",
    "ST_Clpr_list = ST_data_1[:, 0]\n",
    "# 流通股_Trdshr\n",
    "ST_Trdshr_list = ST_data_1[:, 1]\n",
    "# 已上市流通股_Lsttrdshr\n",
    "ST_Lsttrdshr_list = ST_data_1[:, 2]\n",
    "# 每股净资产\n",
    "ST_NAPS_list = ST_data_1[:, 5]\n",
    "\n",
    "# 无风险列表\n",
    "ST_r_list = ST_data_1[:, 4]\n",
    "# 股权收益率波动率列表\n",
    "ST_PriceTheta_list = ST_data_1[:, 3]\n",
    "# 股权市场价值列表\n",
    "ST_E_list = ST_Clpr_list * ST_Lsttrdshr_list + (ST_Trdshr_list - ST_Lsttrdshr_list) * ST_NAPS_list\n",
    "# Short-term Debt (in 10,000)\n",
    "ST_SD_list = ST_data_2[:, 0]\n",
    "# print(ST_SD_list)\n",
    "# Long-term Debt (in 10,000)\n",
    "ST_LD_list = ST_data_2[:, 1]\n",
    "# print(ST_LD_list)\n",
    "\n",
    "\n",
    "# ST*公司数据\n",
    "# 收盘价_Clpr\n",
    "ST_Clpr_list = ST_data_1[:, 0]\n",
    "# 流通股_Trdshr\n",
    "ST_Trdshr_list = ST_data_1[:, 1]\n",
    "# 已上市流通股_Lsttrdshr\n",
    "ST_Lsttrdshr_list = ST_data_1[:, 2]\n",
    "# 每股净资产\n",
    "ST_NAPS_list = ST_data_1[:, 5]\n",
    "\n",
    "# 无风险列表\n",
    "ST_r_list = ST_data_1[:, 4]\n",
    "# 股权收益率波动率列表\n",
    "ST_PriceTheta_list = ST_data_1[:, 3]\n",
    "# 股权市场价值列表\n",
    "ST_E_list = ST_Clpr_list * ST_Lsttrdshr_list + (ST_Trdshr_list - ST_Lsttrdshr_list) * ST_NAPS_list\n",
    "# Short-term Debt (in 10,000)\n",
    "ST_SD_list = ST_data_2[:, 0]\n",
    "# print(ST_SD_list)\n",
    "# Long-term Debt (in 10,000)\n",
    "ST_LD_list = ST_data_2[:, 1]\n",
    "# print(ST_LD_list)\n",
    "\n",
    "\n",
    "# 非ST公司数据\n",
    "# 收盘价_Clpr\n",
    "NST_Clpr_list = NST_data_1[:, 0]\n",
    "# 流通股_Trdshr\n",
    "NST_Trdshr_list = NST_data_1[:, 1]\n",
    "# 已上市流通股_Lsttrdshr\n",
    "NST_Lsttrdshr_list = NST_data_1[:, 2]\n",
    "# 每股净资产\n",
    "NST_NAPS_list = NST_data_1[:, 5]\n",
    "\n",
    "# 无风险列表\n",
    "NST_r_list = NST_data_1[:, 4]\n",
    "# 股权收益率波动率列表\n",
    "NST_PriceTheta_list = NST_data_1[:, 3]\n",
    "# 股权市场价值列表\n",
    "NST_E_list = NST_Clpr_list * NST_Lsttrdshr_list + (NST_Trdshr_list - NST_Lsttrdshr_list) * NST_NAPS_list\n",
    "# Short-term Debt (in 10,000)\n",
    "NST_SD_list = NST_data_2[:, 0]\n",
    "# print(ST_SD_list)\n",
    "# Long-term Debt (in 10,000)\n",
    "NST_LD_list = NST_data_2[:, 1]\n",
    "# print(ST_LD_list)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1.66216759e+09 1.81336320e+09 2.03674080e+09 1.59729799e+09\n",
      " 3.49940800e+09 1.40439078e+09 1.42970069e+09 1.49829600e+09\n",
      " 1.79350080e+09 2.45561686e+09 1.32302478e+09 2.38652952e+09\n",
      " 1.66877120e+09 2.89630450e+09 2.01765152e+09 1.92762692e+09\n",
      " 1.61257816e+09 1.09600570e+09 3.27146251e+09]\n"
     ]
    }
   ],
   "source": [
    "print(ST_E_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 3.80000000e+00  4.37412524e+08  4.37412524e+08 -3.32200000e-01\n",
      "   3.75200000e-02  2.03000000e+00]\n",
      " [ 4.77000000e+00  3.80160000e+08  3.80160000e+08 -5.45300000e-01\n",
      "   3.75200000e-02  5.10000000e-01]\n",
      " [ 8.44000000e+00  2.41320000e+08  2.41320000e+08 -2.55100000e-01\n",
      "   3.75200000e-02  2.50000000e-01]\n",
      " [ 7.89000000e+00  2.02445880e+08  2.02445880e+08 -4.29100000e-01\n",
      "   3.75200000e-02  3.40000000e-01]\n",
      " [ 2.69600000e+01  1.29800000e+08  1.29800000e+08  2.59200000e-01\n",
      "   3.75200000e-02  6.00000000e-02]\n",
      " [ 2.76000000e+00  5.08837238e+08  5.08837238e+08 -5.40000000e-01\n",
      "   3.75200000e-02  2.80000000e-01]\n",
      " [ 6.08000000e+00  2.35148140e+08  2.35148140e+08 -2.30400000e-01\n",
      "   3.75200000e-02  1.27000000e+00]\n",
      " [ 7.66000000e+00  1.95600000e+08  1.95600000e+08 -3.43100000e-01\n",
      "   3.75200000e-02  1.00000000e-02]\n",
      " [ 3.36000000e+00  5.33780000e+08  5.33780000e+08 -2.58300000e-01\n",
      "   3.75200000e-02  5.40000000e-01]\n",
      " [ 6.22000000e+00  3.94793708e+08  3.94793708e+08 -1.11400000e-01\n",
      "   3.75200000e-02  1.60000000e-01]\n",
      " [ 4.15000000e+00  3.28861441e+08  3.18371441e+08 -4.76000000e-01\n",
      "   3.75200000e-02  1.70000000e-01]\n",
      " [ 2.00000000e+00  1.28302099e+09  7.55043154e+08 -6.21900000e-01\n",
      "   3.75200000e-02  1.66000000e+00]\n",
      " [ 4.90000000e+00  3.40565550e+08  3.40565550e+08 -1.63800000e-01\n",
      "   3.75200000e-02  8.80000000e-01]\n",
      " [ 2.35000000e+00  1.23247000e+09  1.23247000e+09 -2.41900000e-01\n",
      "   3.75200000e-02  2.40000000e-01]\n",
      " [ 4.52000000e+00  4.46383080e+08  4.46383080e+08 -4.02100000e-01\n",
      "   3.75200000e-02  9.90000000e-01]\n",
      " [ 1.30000000e+00  1.46432840e+09  1.06432840e+09 -5.23800000e-01\n",
      "   3.75200000e-02  1.36000000e+00]\n",
      " [ 4.73000000e+00  3.41010182e+08  3.40910182e+08 -2.84400000e-01\n",
      "   3.75200000e-02  7.30000000e-01]\n",
      " [ 7.02000000e+00  1.60910082e+08  1.55679074e+08 -4.53700000e-01\n",
      "   3.75200000e-02  6.00000000e-01]\n",
      " [ 4.76000000e+00  6.87282040e+08  6.87282040e+08 -2.59700000e-01\n",
      "   3.75200000e-02 -2.30000000e-01]]\n"
     ]
    }
   ],
   "source": [
    "print(ST_data_1)\n",
    "print(ST_data_2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "F:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py:27: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "F:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py:29: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "F:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py:33: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "F:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py:36: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "F:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py:40: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "F:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py:42: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "'NoneType' object has no attribute 'aim'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-93-17ab73ace55f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m    352\u001b[0m                                                             \u001b[0mselectStyle\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'etour'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    353\u001b[0m                                                             \u001b[0mrecombinStyle\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'xovdprs'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrecopt\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0.9\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpm\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 354\u001b[1;33m                                                             distribute=True, drawing=1)\n\u001b[0m\u001b[0;32m    355\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    356\u001b[0m     \u001b[1;31m# output results\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\Anaconda\\lib\\site-packages\\geatpy\\lib64/v3.6\\sga_new_real_templet.pyd\u001b[0m in \u001b[0;36msga_new_real_templet.sga_new_real_templet\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'aim'"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "\"\"\"             *****main.py*****\n",
    "use GA algorithm to search the sentence: Tom is a little boy.\n",
    "\"\"\"\n",
    "from scipy import stats\n",
    "from scipy.optimize import fsolve\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import geatpy as ga\n",
    "\n",
    "# 公司总样本数\n",
    "N = 32\n",
    "# 公司数\n",
    "count = int((N / 2))\n",
    "\n",
    "# 读取ST上市公司数据\n",
    "ST_data_xls_1 = pd.read_excel(\"ST公司数据.xls\")\n",
    "ST_data_xls_2 = pd.read_excel(\"ST公司数据负债.xls\")\n",
    "# 读取ST*上市公司数据\n",
    "ST_Plus_data_xls_1 = pd.read_excel(\"ST+公司数据.xls\")\n",
    "ST_Plus_data_xls_2 = pd.read_excel(\"ST+公司数据负债.xls\")\n",
    "# 读取非ST上市公司数据\n",
    "NST_data_xls_1 = pd.read_excel(\"非ST公司数据.xls\")\n",
    "NST_data_xls_2 = pd.read_excel(\"非ST公司数据负债.xls\")\n",
    "\n",
    "# 读取ST上市公司数据\n",
    "ST_data_1 = ST_data_xls_1.ix[: count,\n",
    "            ['收盘价_Clpr', '流通股_Trdshr', '已上市流通股_Lsttrdshr', '年收益率_Yrret', '年无风险收益率_Yrrfret', '每股净资产(元/股)_NAPS']].values\n",
    "ST_data_2 = ST_data_xls_2.ix[: count,\n",
    "            ['流动负债合计(元)_TotCurLia', '非流动负债合计(元)_TotNCurLia', '负债合计(元)_TotLiab']].values\n",
    "\n",
    "# 读取ST*上市公司数据\n",
    "ST_Plus_data_1 = ST_Plus_data_xls_1.ix[: count,\n",
    "                 ['收盘价_Clpr', '流通股_Trdshr', '已上市流通股_Lsttrdshr', '年收益率_Yrret', '年无风险收益率_Yrrfret',\n",
    "                  '每股净资产(元/股)_NAPS']].values\n",
    "ST_Plus_data_2 = ST_Plus_data_xls_2.ix[: count,\n",
    "                 ['流动负债合计(元)_TotCurLia', '非流动负债合计(元)_TotNCurLia', '负债合计(元)_TotLiab']].values\n",
    "\n",
    "# 读取非ST上市公司数据\n",
    "NST_data_1 = NST_data_xls_1.ix[: N,\n",
    "             ['收盘价_Clpr', '流通股_Trdshr', '已上市流通股_Lsttrdshr', '年收益率_Yrret', '年无风险收益率_Yrrfret', '每股净资产(元/股)_NAPS']].values\n",
    "NST_data_2 = NST_data_xls_2.ix[: N,\n",
    "             ['流动负债合计(元)_TotCurLia', '非流动负债合计(元)_TotNCurLia', '负债合计(元)_TotLiab']].values\n",
    "\n",
    "# ST公司的数据，分别对应Stock Name Code\n",
    "# Long-term Debt (in 10,000)\n",
    "# Short-term Debt (in 10,000)\n",
    "# Equity value Volatility\n",
    "# Asset Value (in 10,000)\n",
    "# Asset value Volatility\n",
    "ST_data = np.array([[2464.16, 1679.16, 36.14 * 0.01, 3.2806 * 100000, 35.69 * 0.01],\n",
    "                    [231.08, 46608.83, 53.86 * 0.01, 5.7626 * 100000, 49.55 * 0.01],\n",
    "                    [86799.25, 514562.55, 50.05 * 0.01, 1.8846 * 1000000, 34.33 * 0.01],\n",
    "                    [11020, 118744.87, 47.00 * 0.01, 4.8354 * 100000, 34.58 * 0.01],\n",
    "                    [42880.93, 654830.19, 43.81 * 0.01, 1.2406 * 1000000, 19.56 * 0.01],\n",
    "                    [11694.35, 26511.75, 58.62 * 0.01, 4.0832 * 100000, 53.22 * 0.01],\n",
    "                    [280, 30921.93, 37.92 * 0.01, 4.2935 * 100000, 35.21 * 0.01],\n",
    "                    [4632.06, 9030.8, 49.62 * 0.01, 4.0429 * 100000, 47.97 * 0.01],\n",
    "                    [14824.35, 28572.55, 88.39 * 0.01, 7.5958 * 100000, 83.42 * 0.01],\n",
    "                    [0, 25853.35, 61.04 * 0.01, 3.6784 * 100000, 56.81 * 0.01],\n",
    "                    [840453.26, 1462137.04, 59.50 * 0.01, 4.2255 * 1000000, 27.86 * 0.01],\n",
    "                    [34009.89, 428458.70, 60.14 * 0.01, 8.4188 * 100000, 27.92 * 0.01],\n",
    "                    [22407.02, 27855.54, 59.69 * 0.01, 4.1698 * 100000, 52.61 * 0.01],\n",
    "                    [6186.36, 40232.46, 72.28 * 0.01, 2.5464 * 100000, 59.35 * 0.01],\n",
    "                    [6279.19, 131031.18, 54.89 * 0.01, 7.431 * 100000, 44.90 * 0.01],\n",
    "                    [10135.53, 9332.03, 51.37 * 0.01, 5.5372 * 100000, 49.59 * 0.01],\n",
    "                    [207.59, 87219.86, 74.82 * 0.01, 5.7713 * 100000, 63.69 * 0.01],\n",
    "                    [93230.53, 699453.1191, 48.72 * 0.01, 2.1436 * 1000000, 30.99 * 0.01],\n",
    "                    [3488.28, 31903.07, 66.34 * 0.01, 5.0906 * 100000, 61.80 * 0.01],\n",
    "                    [10074.08, 99352.06, 60.82 * 0.01, 7.0996 * 100000, 51.59 * 0.01]\n",
    "                    ])\n",
    "\n",
    "# 非ST公司的数据，分别对应Stock Name Code\n",
    "# Long-term Debt (in 10,000)\n",
    "# Short-term Debt (in 10,000)\n",
    "# Equity value Volatility\n",
    "# Asset Value (in 10,000)\n",
    "# Asset value Volatility\n",
    "No_ST_data = np.array([[45.13, 7668.44, 46.04 * 0.01, 4.2542 * 100000, 45.39 * 0.01],\n",
    "                       [0, 37144.86, 50.21 * 0.01, 2.7804 * 1000000, 45.89 * 0.01],\n",
    "                       [80308.42, 976510.53, 48.34 * 0.01, 6.5506 * 1000000, 30 * 0.01],\n",
    "                       [541031.15, 3704815.33, 31.98 * 0.01, 9.9624 * 100000, 11.56 * 0.01],\n",
    "                       [178233.18, 36331.9, 32.73 * 0.01, 6.6378 * 100000, 25.78 * 0.01],\n",
    "                       [675.48, 79838.90, 53.52 * 0.01, 5.9539 * 100000, 47.13 * 0.01],\n",
    "                       [8996.06, 105485, 50.46 * 0.01, 6.0319 * 1000000, 40.90 * 0.01],\n",
    "                       [1794588.08, 2489400.99, 43.67 * 0.01, 5.8471 * 100000, 13.16 * 0.01],\n",
    "                       [1813.00, 27476.40, 63.17 * 0.01, 1.6958 * 1000000, 60.05 * 0.01],\n",
    "                       [378522.71, 356220.27, 45.59 * 0.01, 2.7886 * 10000000, 26.14 * 0.01],\n",
    "                       [54500.72, 196309.76, 53.55 * 0.01, 9.0138 * 100000, 53.08 * 0.01],\n",
    "                       [18278.26, 380425.30, 48.48 * 0.01, 7.0709 * 1000000, 27.38 * 0.01],\n",
    "                       [926880.33, 1248327, 37.96 * 0.01, 1.4205 * 1000000, 26.46 * 0.01],\n",
    "                       [124549.82, 463604.49, 50.72 * 0.01, 5.3226 * 1000000, 30.06 * 0.01],\n",
    "                       [901667.26, 1228475.16, 45.99 * 0.01, 1.6609 * 1000000, 27.64 * 0.01],\n",
    "                       [1113.75, 134160.86, 46.06 * 0.01, 1.2401 * 10000000, 42.36 * 0.01],\n",
    "                       [3480969.99, 2176465.73, 42.04 * 0.01, 6.062 * 1000000, 23.15 * 0.01],\n",
    "                       [1243193.37, 2206873.92, 53.83 * 0.01, 6.0223 * 1000000, 23.80 * 0.01],\n",
    "                       [982967.19, 404512.50, 35.06 * 0.01, 1.2234 * 1000000, 27.11 * 0.01],\n",
    "                       [8341.26, 274337.17, 39.56 * 0.01, 4.2542 * 100000, 30.56 * 0.01]\n",
    "                       ])\n",
    "\n",
    "# 计算结果，分别对应Stock Name DD EDF Stock Name DD EDF\n",
    "result_array = np.array([[\"*ST Hongsheng\", 2.7833, 0.27 * 0.01, \"Quanxinhao\", 2.1719, 1.49 * 0.01, ],\n",
    "                         [\"*ST Yunsheng\", 1.8548, 3.18 * 0.01, \"Lvjing\", 1.9888, 2.34 * 0.01, ],\n",
    "                         [\"*ST Fantai\", 2.0911, 1.83 * 0.01, \"Hanggang\", 2.1429, 1.61 * 0.01, ],\n",
    "                         [\"*ST Jizhuang\", 2.1688, 1.505 * 0.01, \"Xugong\", 3.6151, 0.02 * 0.01, ],\n",
    "                         [\"*ST Zhengmei\", 2.3789, 0.868 * 0.01, \"Shanghai Energy\", 3.5984, 0.016 * 0.01, ],\n",
    "                         [\"ST Shanshui\", 1.7462, 4.039 * 0.01, \"Dasheng Cultural\", 1.8662, 3.1 * 0.01, ],\n",
    "                         [\"ST Jinggu\", 2.6355, 0.42 * 0.01, \"Shennong Gene\", 2.0044, 2.25 * 0.01, ],\n",
    "                         [\"S*ST Qianfeng\", 2.0333, 2.1 * 0.01, \"Greattown\", 4.0114, 0.003 * 0.01, ],\n",
    "                         [\"*ST Tianyi\", 1.149, 12.53 * 0.01, \"Xiyi\", 1.5859, 5.64 * 0.01, ],\n",
    "                         [\"*ST Xinmei\", 1.6365, 5.09 * 0.01, \"Vantone\", 2.8508, 0.22 * 0.01, ],\n",
    "                         [\"*ST Shunchuan\", 2.2047, 1.37 * 0.01, \"Jiuding Investment\", 1.8701, 3.07 * 0.01, ],\n",
    "                         [\"*ST Sanwei\", 1.7297, 4.18 * 0.01, \"Black Cat\", 2.0959, 1.8 * 0.01, ],\n",
    "                         [\"*ST Pitu\", 1.7536, 3.98 * 0.01, \"Leshi, Internet\", 3.0135, 0.13 * 0.01, ],\n",
    "                         [\"*ST Jinyu\", 1.4105, 7.92 * 0.01, \"Cgn Nuclear\", 2.1827, 1.45 * 0.01, ],\n",
    "                         [\"*ST Jiadian\", 1.8307, 3.36 * 0.01, \"Chint Electrics\", 2.66, 0.39 * 0.01, ],\n",
    "                         [\"*ST Huke\", 1.9751, 2.41 * 0.01, \"Greatstar\", 2.1696, 1.5 * 0.01, ],\n",
    "                         [\"*ST Hehua\", 1.3327, 9.13 * 0.01, \"Salt Lake\", 3.319, 0.045 * 0.01, ],\n",
    "                         [\"*ST Dayou\", 2.1462, 1.59 * 0.01, \"Xishan\", 2.4995, 0.62 * 0.01, ],\n",
    "                         [\"*ST Changjiu\", 1.5145, 6.49 * 0.01, \"Wanhua\", 3.321, 0.045 * 0.01, ],\n",
    "                         [\"*ST Aifu\", 1.6617, 4.83 * 0.01, \"Huayi Electric\", 2.5343, 0.56 * 0.01]\n",
    "                         ])\n",
    "\n",
    "\n",
    "def calculate_DD(i, counter, r_list, SD_list, LD_list, a, b, D_list, PriceTheta_list, E_list, IS_ST_bool):\n",
    "    \"\"\"\n",
    "        计算DD距离并返归m，n值\n",
    "    \"\"\"\n",
    "    m = 0\n",
    "    n = 0\n",
    "    for time in range(counter):\n",
    "        # 利用KMV模型计算\n",
    "        r = r_list[time]  # 无风险利率\n",
    "        T = 1  # 期权到期时间，以年为单位\n",
    "        SD = SD_list[time]  # SD为长期负债 （单位：元）\n",
    "        LD = LD_list[time]  # LD短期负债 （单位：元）\n",
    "        DP = a[i] * SD + b[i] * LD  # 违约触发点DPT # DP=（TD-LD） +0.5LD （7） 其中：TD为总负债；LD为长期负债。 （单位：元）\n",
    "        D = D_list[time]  # D=TD-LD+0.5∗LD  债券的面值是D （单位：元）\n",
    "        PriceTheta = PriceTheta_list[time]  # 交易波动率，可以是日月年的数据 （单位：%）\n",
    "        EquityTheta = PriceTheta  # 股权收益率的波动率σE\n",
    "        E = E_list[time]  # 公司股票的市场价值 （单位：元）\n",
    "        Va, AssetTheta = KMVOptSearch(E, D, r, T, EquityTheta)  # 资产价值VA（单位：元）资产收益率波动率σA\n",
    "        AssetTheta = AssetTheta  # 资产收益率波动率σA （单位：%）\n",
    "        DD = (Va - DP) / (Va * AssetTheta)  # 违约距离DD\n",
    "        EDF = stats.norm.cdf(-DD)  # 预期违约概率EDF（单位：%）\n",
    "        # print(\"ST_DD = {}\".format(DD))\n",
    "        if IS_ST_bool == 1:\n",
    "            if DD >= 0:\n",
    "                m += 1\n",
    "        elif IS_ST_bool == 0:\n",
    "            if DD < 0:\n",
    "                n += 1\n",
    "\n",
    "    return [m, n]\n",
    "\n",
    "\n",
    "# 计算KMV模型\n",
    "def KMVOptSearch(E, D, r, T, EquityTheta):\n",
    "    # print(\"E:\", E)\n",
    "    # print(\"D:\", D)\n",
    "    EtoD = float(E) / float(D)\n",
    "\n",
    "    # print(\"EtoD：\", EtoD)\n",
    "    # print()\n",
    "    # global i\n",
    "    # i = 1\n",
    "\n",
    "    def KMVfun(x, EtoD, r, T, EquityTheta):\n",
    "        EtoD, r, T, EquityTheta = float(EtoD), float(r), float(T), float(EquityTheta)\n",
    "        d1 = (np.log(x[0] * EtoD) + (r + 0.5 * x[1] ** 2) * T) / (x[1] * np.sqrt(T))\n",
    "        d2 = d1 - x[1] * np.sqrt(T)\n",
    "        # global i\n",
    "        # print(\"第{}次计算：\".format(i))\n",
    "        # i += 1\n",
    "        # print(x[0], x[1])\n",
    "        # print(x[0] * stats.norm.cdf(d1, 0.0, 1.0) - np.exp(-r * T) * stats.norm.cdf(d2, 0.0, 1.0) / EtoD - 1,\n",
    "        #       stats.norm.cdf(d1, 0.0, 1.0) * x[0] * x[1] - EquityTheta\n",
    "        #       )\n",
    "        # print()\n",
    "        return [\n",
    "            x[0] * stats.norm.cdf(d1, 0.0, 1.0) - np.exp(-r * T) * stats.norm.cdf(d2, 0.0, 1.0) / EtoD - 1,\n",
    "            stats.norm.cdf(d1, 0.0, 1.0) * x[0] * x[1] - EquityTheta\n",
    "        ]\n",
    "\n",
    "    # print()\n",
    "    VaThetaX = fsolve(KMVfun, [1, 1111], args=(EtoD, r, T, EquityTheta))\n",
    "    Va = VaThetaX[0] * E\n",
    "    AssetTheta = VaThetaX[1]\n",
    "    return Va, AssetTheta\n",
    "\n",
    "\n",
    "\"\"\"\n",
    "# 读取ST上市公司数据\n",
    "ST_data_1 = ST_data_xls_1.ix[:18,\n",
    "            ['收盘价_Clpr', '流通股_Trdshr', '已上市流通股_Lsttrdshr', '年收益率_Yrret', '年无风险收益率_Yrrfret', '每股净资产(元/股)_NAPS']].values\n",
    "ST_data_2 = ST_data_xls_2.ix[:18, ['流动负债合计(元)_TotCurLia', '非流动负债合计(元)_TotNCurLia', '负债合计(元)_TotLiab']].values\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "# ST公司数据\n",
    "# 收盘价_Clpr\n",
    "ST_Clpr_list = ST_data_1[:, 0]\n",
    "# 流通股_Trdshr\n",
    "ST_Trdshr_list = ST_data_1[:, 1]\n",
    "# 已上市流通股_Lsttrdshr\n",
    "ST_Lsttrdshr_list = ST_data_1[:, 2]\n",
    "# 每股净资产\n",
    "ST_NAPS_list = ST_data_1[:, 5]\n",
    "\n",
    "# 无风险列表\n",
    "ST_r_list = ST_data_1[:, 4]\n",
    "# 股权收益率波动率列表\n",
    "ST_PriceTheta_list = ST_data_1[:, 3]\n",
    "# 股权市场价值列表\n",
    "ST_E_list = ST_Clpr_list * ST_Lsttrdshr_list + (ST_Trdshr_list - ST_Lsttrdshr_list) * ST_NAPS_list\n",
    "# Short-term Debt (in 10,000)\n",
    "ST_SD_list = ST_data_2[:, 0]\n",
    "# print(ST_SD_list)\n",
    "# Long-term Debt (in 10,000)\n",
    "ST_LD_list = ST_data_2[:, 1]\n",
    "# print(ST_LD_list)\n",
    "# 负债合计\n",
    "ST_D_list = ST_data_2[:, 2]\n",
    "\n",
    "# ST*公司数据\n",
    "# 收盘价_Clpr\n",
    "ST_Plus_Clpr_list = ST_Plus_data_1[:, 0]\n",
    "# 流通股_Trdshr\n",
    "ST_Plus_Trdshr_list = ST_Plus_data_1[:, 1]\n",
    "# 已上市流通股_Lsttrdshr\n",
    "ST_Plus_Lsttrdshr_list = ST_Plus_data_1[:, 2]\n",
    "# 每股净资产\n",
    "ST_Plus_NAPS_list = ST_Plus_data_1[:, 5]\n",
    "\n",
    "# 无风险列表\n",
    "ST_Plus_r_list = ST_Plus_data_1[:, 4]\n",
    "# 股权收益率波动率列表\n",
    "ST_Plus_PriceTheta_list = ST_data_1[:, 3]\n",
    "# 股权市场价值列表\n",
    "ST_Plus_E_list = ST_Plus_Clpr_list * ST_Plus_Lsttrdshr_list + (\n",
    "        ST_Plus_Trdshr_list - ST_Plus_Lsttrdshr_list) * ST_Plus_NAPS_list\n",
    "# Short-term Debt (in 10,000)\n",
    "ST_Plus_SD_list = ST_Plus_data_2[:, 0]\n",
    "# print(ST_SD_list)\n",
    "# Long-term Debt (in 10,000)\n",
    "ST_Plus_LD_list = ST_Plus_data_2[:, 1]\n",
    "# print(ST_LD_list)\n",
    "# 负债合计\n",
    "ST_Plus_D_list = ST_Plus_data_2[:, 2]\n",
    "\n",
    "# 非ST公司数据\n",
    "# 收盘价_Clpr\n",
    "NST_Clpr_list = NST_data_1[:, 0]\n",
    "# 流通股_Trdshr\n",
    "NST_Trdshr_list = NST_data_1[:, 1]\n",
    "# 已上市流通股_Lsttrdshr\n",
    "NST_Lsttrdshr_list = NST_data_1[:, 2]\n",
    "# 每股净资产\n",
    "NST_NAPS_list = NST_data_1[:, 5]\n",
    "\n",
    "# 无风险列表\n",
    "NST_r_list = NST_data_1[:, 4]\n",
    "# 股权收益率波动率列表\n",
    "NST_PriceTheta_list = NST_data_1[:, 3]\n",
    "# 股权市场价值列表\n",
    "NST_E_list = NST_Clpr_list * NST_Lsttrdshr_list + (NST_Trdshr_list - NST_Lsttrdshr_list) * NST_NAPS_list\n",
    "# Short-term Debt (in 10,000)\n",
    "NST_SD_list = NST_data_2[:, 0]\n",
    "# print(ST_SD_list)\n",
    "# Long-term Debt (in 10,000)\n",
    "NST_LD_list = NST_data_2[:, 1]\n",
    "# 负债合计\n",
    "NST_D_list = NST_data_2[:, 2]\n",
    "\n",
    "\n",
    "# Attention: you had better put the aim-function in another file.\n",
    "def aim(Phen, LegV):  # define the aim function\n",
    "\n",
    "    global counter\n",
    "    counter += 1\n",
    "    print(\"第{}次迭代开始：\".format(counter))\n",
    "\n",
    "    print(Phen)\n",
    "\n",
    "    for i in range(Phen.shape[0]):\n",
    "        # print(\"N = \", N)\n",
    "        n = 0\n",
    "        m = 0\n",
    "        a = Phen[:, 0]\n",
    "        # print(\"a:\", a)\n",
    "        b = Phen[:, 1]\n",
    "        # print(\"b:\", b)\n",
    "\n",
    "        mn_list = calculate_DD(i, count, ST_r_list, ST_SD_list, ST_LD_list, a, b, ST_D_list, ST_PriceTheta_list, ST_E_list,\n",
    "                               1)\n",
    "        m += mn_list[0]\n",
    "        n += mn_list[1]\n",
    "\n",
    "        mn_list = calculate_DD(i, count, ST_Plus_r_list, ST_Plus_SD_list, ST_Plus_LD_list, a, b, ST_Plus_D_list,\n",
    "                               ST_Plus_PriceTheta_list, ST_Plus_E_list, 1)\n",
    "        m += mn_list[0]\n",
    "        n += mn_list[1]\n",
    "\n",
    "        mn_list = calculate_DD(i, N, NST_r_list, NST_SD_list, NST_LD_list, a, b, NST_D_list, NST_PriceTheta_list,\n",
    "                               NST_E_list, 0)\n",
    "        m += mn_list[0]\n",
    "        n += mn_list[1]\n",
    "\n",
    "        print(\"i:\", i + 1)\n",
    "        print(\"a = {}, b = {}\".format(a[i], b[i]))\n",
    "        print(\"m = {}, n = {}\".format(m, n))\n",
    "        # print(1 - ((m + n) / N))\n",
    "        Mis_rate = 1 - ((m + n) / (N * 2))\n",
    "        print(\"Mis_rate：\", Mis_rate)\n",
    "        if i == 0:\n",
    "            diff = np.array([[Mis_rate]])\n",
    "        else:\n",
    "            diff = np.append(diff, [[Mis_rate]], axis=0)\n",
    "        print(\"diff.shape:\", diff.shape)\n",
    "        print()\n",
    "\n",
    "    print(\"[diff, LegV][diff, LegV][diff, LegV][diff, LegV]:\", [diff, LegV])\n",
    "    return [diff, LegV]\n",
    "\n",
    "\n",
    "global counter\n",
    "counter = 0\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    AIM_M = __import__('aimfuc')\n",
    "    AIM_M = __import__('main')  # get the handle of aim-function\n",
    "    # variables setting\n",
    "\n",
    "    # 变量设置\n",
    "    x1 = [0, 5]  # 自变量1的范围\n",
    "    x2 = [0, 5]  # 自变量2的范围\n",
    "    b1 = [0, 1]  # 自变量1是否包含下界\n",
    "    b2 = [0, 1]  # 自变量2是否包含上界\n",
    "\n",
    "    ranges = np.vstack([x1, x2]).T  # 生成自变量的范围矩阵\n",
    "    # print(ranges)\n",
    "    borders = np.vstack([b1, b2]).T  # 生成自变量的边界矩阵\n",
    "    # print(borders)\n",
    "    # 生成区域描述器\n",
    "    # help(ga.crtfld)\n",
    "    FieldDR = ga.crtfld(ranges, borders)  # create FieldDR\n",
    "    # print(FieldDR)\n",
    "\n",
    "    # call the GEA algorithm template\n",
    "    [pop_trace, var_trace, times] = ga.sga_new_real_templet(AIM_M, 'aim', None, None, FieldDR, problem='R', maxormin=1,\n",
    "                                                            MAXGEN=10, NIND=10, SUBPOP=1, GGAP=0.9,\n",
    "                                                            selectStyle='etour',\n",
    "                                                            recombinStyle='xovdprs', recopt=0.9, pm=None,\n",
    "                                                            distribute=True, drawing=1)\n",
    "\n",
    "    # output results\n",
    "    for num in var_trace[np.argmin(pop_trace[:, 1]), :]:\n",
    "        print(chr(int(num)), end='')\n",
    "\n",
    "    # help(ga.sga_new_real_templet)\n",
    "    \"\"\"\n",
    "    sga_new_real_templet(AIM_M, AIM_F, PUN_M, PUN_F, FieldDR, problem, maxormin, MAXGEN, NIND, SUBPOP, GGAP, selectStyle, recombinStyle, recopt, pm, distribute, drawing=1)\n",
    "    sga_new_real_templet.py - 改进的单目标编程模板(实值编码)\n",
    "\n",
    "    本模板实现改进单目标编程模板(实值编码)，将父子两代合并进行选择，增加了精英保留机制\n",
    "\n",
    "    语法：\n",
    "        该函数除了drawing外，不设置可缺省参数。当某个参数需要缺省时，在调用函数时传入None即可。\n",
    "        比如当没有罚函数时，则在调用编程模板时将第3、4个参数设置为None即可，如：\n",
    "        sga_new_real_templet(AIM_M, 'aimfuc', None, None, ..., maxormin)\n",
    "\n",
    "    输入参数：\n",
    "        AIM_M - 目标函数的地址，由AIM_M = __import__('目标函数所在文件名')语句得到\n",
    "                目标函数规范定义：[f,LegV] = aimfuc(Phen,LegV)\n",
    "                其中Phen是种群的表现型矩阵, LegV为种群的可行性列向量,f为种群的目标函数值矩阵\n",
    "\n",
    "        AIM_F : str - 目标函数名\n",
    "\n",
    "        PUN_M - 罚函数的地址，由PUN_M = __import__('罚函数所在文件名')语句得到\n",
    "                罚函数规范定义： newFitnV = punishing(LegV, FitnV)\n",
    "                其中LegV为种群的可行性列向量, FitnV为种群个体适应度列向量\n",
    "                一般在罚函数中对LegV为0的个体进行适应度惩罚，返回修改后的适应度列向量newFitnV\n",
    "\n",
    "        PUN_F : str - 罚函数名\n",
    "\n",
    "        FieldDR : array - 实际值种群区域描述器\n",
    "            [lb;            (float) 指明每个变量使用的下界\n",
    "             ub]            (float) 指明每个变量使用的上界\n",
    "             注：不需要考虑是否包含变量的边界值。在crtfld中已经将是否包含边界值进行了处理\n",
    "             本函数生成的矩阵的元素值在FieldDR的[下界, 上界)之间\n",
    "\n",
    "        problem : str - 表明是整数问题还是实数问题，'I'表示是整数问题，'R'表示是实数问题                 \n",
    "\n",
    "        maxormin int - 最小最大化标记，1表示目标函数最小化；-1表示目标函数最大化\n",
    "\n",
    "        MAXGEN : int - 最大遗传代数\n",
    "\n",
    "        NIND : int - 种群规模，即种群中包含多少个个体\n",
    "\n",
    "        SUBPOP : int - 子种群数量，即对一个种群划分多少个子种群\n",
    "\n",
    "        GGAP : float - 代沟，本模板中该参数为无用参数，仅为了兼容同类的其他模板而设\n",
    "\n",
    "        selectStyle : str - 指代所采用的低级选择算子的名称，如'rws'(轮盘赌选择算子)\n",
    "\n",
    "        recombinStyle: str - 指代所采用的低级重组算子的名称，如'xovsp'(单点交叉)\n",
    "\n",
    "        recopt : float - 交叉概率\n",
    "\n",
    "        pm : float - 重组概率\n",
    "\n",
    "        distribute : bool - 是否增强种群的分布性（可能会造成收敛慢）\n",
    "\n",
    "        drawing : int - (可选参数)，0表示不绘图，1表示绘制最终结果图，2表示绘制动画。默认drawing为1\n",
    "\n",
    "    输出参数：\n",
    "        pop_trace : array - 种群进化记录器(进化追踪器),\n",
    "                            第0列记录着各代种群最优个体的目标函数值\n",
    "                            第1列记录着各代种群的适应度均值\n",
    "                            第2列记录着各代种群最优个体的适应度值\n",
    "\n",
    "        var_trace : array - 变量记录器，记录着各代种群最优个体的变量值，每一列对应一个控制变量\n",
    "\n",
    "        times     : float - 进化所用时间\n",
    "\n",
    "    模板使用注意：\n",
    "        1.本模板调用的目标函数形如：[ObjV,LegV] = aimfuc(Phen,LegV), \n",
    "          其中Phen表示种群的表现型矩阵, LegV为种群的可行性列向量(详见Geatpy数据结构)\n",
    "        2.本模板调用的罚函数形如: newFitnV = punishing(LegV, FitnV), \n",
    "          其中FitnV为用其他算法求得的适应度\n",
    "        若不符合上述规范，则请修改算法模板或自定义新算法模板\n",
    "        3.关于'maxormin': geatpy的内核函数全是遵循“最小化目标”的约定的，即目标函数值越小越好。\n",
    "          当需要优化最大化的目标时，需要设置'maxormin'为-1。\n",
    "          本算法模板是正确使用'maxormin'的典型范例，其具体用法如下：\n",
    "          当调用的函数传入参数包含与“目标函数值矩阵”有关的参数(如ObjV,ObjVSel,NDSetObjV等)时，\n",
    "          查看该函数的参考资料(可用'help'命令查看，也可到官网上查看相应的教程)，\n",
    "          里面若要求传入前对参数乘上'maxormin',则需要乘上。\n",
    "          里面若要求对返回参数乘上'maxormin'进行还原，\n",
    "          则调用函数返回得到的相应参数需要乘上'maxormin'进行还原，否则其正负号就会被改变。\n",
    "    \"\"\"\n",
    "\n",
    "\"\"\"\n",
    "# 无风险列表\n",
    "ST_r_list = [0.15] * count\n",
    "# 股权收益率波动率列表\n",
    "ST_PriceTheta_list = ST_data[:, 3]\n",
    "# 股权市场价值列表\n",
    "ST_E_list = ST_data[:, -2]\n",
    "# Long-term Debt (in 10,000)\n",
    "ST_LD_list = ST_data[:, 0]\n",
    "# print(ST_LD_list)\n",
    "# Short-term Debt (in 10,000)\n",
    "ST_SD_list = ST_data[:, 1]\n",
    "# print(ST_SD_list)\n",
    "# Equity value Volatility\n",
    "ST_Equity_value = ST_data[:, 2]\n",
    "# print(ST_Equity_value)\n",
    "\n",
    "\n",
    "# 股权收益率波动率列表\n",
    "NST_PriceTheta_list = No_ST_data[:, 3]\n",
    "# 股权市场价值列表\n",
    "NST_E_list = No_ST_data[:, -2]\n",
    "# Long-term Debt (in 10,000)\n",
    "NST_LD_list = No_ST_data[:, 0]\n",
    "# print(ST_LD_list)\n",
    "# Short-term Debt (in 10,000)\n",
    "NST_SD_list = No_ST_data[:, 1]\n",
    "# print(ST_SD_list)\n",
    "# Equity value Volatility\n",
    "NST_Equity_value = No_ST_data[:, 2]\n",
    "# print(NST_Equity_value)\n",
    "\"\"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[3.80000000e+00 4.37412524e+08]\n",
      " [4.77000000e+00 3.80160000e+08]\n",
      " [8.44000000e+00 2.41320000e+08]\n",
      " [7.89000000e+00 2.02445880e+08]\n",
      " [2.69600000e+01 1.29800000e+08]\n",
      " [2.76000000e+00 5.08837238e+08]\n",
      " [6.08000000e+00 2.35148140e+08]\n",
      " [7.66000000e+00 1.95600000e+08]\n",
      " [3.36000000e+00 5.33780000e+08]\n",
      " [6.22000000e+00 3.94793708e+08]\n",
      " [4.15000000e+00 3.18371441e+08]\n",
      " [2.00000000e+00 7.55043154e+08]\n",
      " [4.90000000e+00 3.40565550e+08]\n",
      " [2.35000000e+00 1.23247000e+09]\n",
      " [4.52000000e+00 4.46383080e+08]\n",
      " [1.30000000e+00 1.06432840e+09]\n",
      " [4.73000000e+00 3.40910182e+08]\n",
      " [7.02000000e+00 1.55679074e+08]\n",
      " [4.76000000e+00 6.87282040e+08]]\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
